<?php

namespace app\api\controller;

use app\admin\model\article\ArticleSee;
use app\admin\model\article\Message;
use app\admin\model\article\OnlineVideo;
use app\admin\model\article\Works;
use app\admin\model\user\TeacherCategory;
use app\admin\model\UserCollection;
use app\admin\model\article\WorksCategory;
use app\common\controller\Api;
use think\Db;
use think\Validate;

/**
 * 文章模块
 * @ApiWeigh (20)
 */
class Article extends Api
{
    protected $noNeedLogin = ["getSystemArticleInfo","getMessageList","getMessageInfo","getQuestionList"];
    protected $noNeedRight = ['*'];



    /**
     * 获取系统文章
     * @ApiWeigh (100)
     * @ApiMethod   (POST)
     * @ApiParams   (name="name", type="string", required=true, description="系统文章标识school_history:学校历史;send_other_pay:发起代付说明;other_pay:代付说明;vip_rights:会员权益;recharge_tip:充值说明;vourse_service_agreement:课程服务协议；integral_exchange：积分兑换")
     * @ApiReturnParams   (name="title", type="string", required=true, description="文章名称")
     * @ApiReturnParams   (name="content", type="string", required=true, description="文章内容")
     */
    public function getSystemArticleInfo(){
        $name = $this->request->post("name");
        $articleModel = new \app\admin\model\article\Article();
        try {
            $condition = [
                "tag" => $name,
            ];
            $info = $articleModel->getInfo($condition, $this->auth->getUser());
        }catch (\Exception $e){
            $this->error($e->getMessage());
        }

        $this->success("查询成功", $info);

    }

    /**
     * 消息列表
     * @ApiMethod   (POST)
     * @ApiWeigh (90)
     * @ApiParams   (name="page", type="integer", required=true, description="页码")
     * @ApiReturnParams   (name="title", type="string", required=true, description="主标题")
     * @ApiReturnParams   (name="des", type="string", required=true, description="副标题")
     * @ApiReturnParams   (name="createtime", type="int", required=true, description="创建时间")
     * @ApiReturnParams   (name="type", type="int", required=true, description="类型：100：系统公告；101：用户消息")
     * @ApiReturnParams   (name="message_type", type="int", required=true, description="用户消息类型")
     */
    public function getMessageList()
    {
        $messageModel = new Message();
        $list = $messageModel->getList([],$this->auth->getUser());

        $this->success("查询成功", $list);
    }

    /**
     * 获取消息详情
     * @ApiMethod   (POST)
     * @ApiWeigh (89)
     * @ApiParams   (name="id", type="string", required=true, description="消息id")
     * @ApiReturnParams   (name="title", type="string", required=true, description="文章名称")
     * @ApiReturnParams   (name="content", type="string", required=true, description="文章内容")
     */
    public function getMessageInfo(){
        $id = $this->request->post("id");
        $messageModel = new \app\admin\model\article\Message();
        try {
            $condition = [
                "id" => $id,
            ];
            $info = $messageModel->getInfo($condition, $this->auth->getUser());
        }catch (\Exception $e){
            $this->error($e->getMessage());
        }

        $this->success("查询成功", $info);

    }

    /**
     * 获取问答列表
     * @ApiMethod   (POST)
     * @ApiWeigh (80)
     */
    public function getQuestionList(){

        $questionModel = new \app\admin\model\article\Question();
        try {
            $condition = [

            ];
            $info = $questionModel->getList($condition);
        }catch (\Exception $e){
            $this->error($e->getMessage());
        }

        $this->success("查询成功", $info);

    }

}
